#include "ShellInvoke.h"
#include <QDebug>
#include <QProcess>

ShellInvoke::ShellInvoke(){
    innerProcess = new QProcess(this);
    m_waitFor="start";
}

void ShellInvoke::shellAction(QString str, QStringList sArg){
    qDebug() << "exec action: " << str;
    qDebug() << "arg: " << sArg;
    //*innerProcess = new QProcess(this);
    //QString film = QString::fromUtf8("/home/emugwaneza/Vidéos/Babysitters (2007) Dra.avi");
    QProcess* secProc = new QProcess(this);
    /*if(m_waitFor=="start"){
        QProcess* secProc = new QProcess(this);
    }*/
    secProc->start(str,sArg);
    qDebug() << "lounched";
        if ((m_waitFor=="start") && !secProc->waitForStarted(-1))
            qDebug() << "Start failed:" << secProc->errorString();
        else if ((m_waitFor=="finish") && !secProc->waitForFinished(-1 ) )
            qDebug() << "Finished failed:" << secProc->errorString();
        else {
            m_response = secProc->readAll();
            qDebug() << "Succeed output:" << m_response;
        }
    qDebug() << "finished";
}

QString ShellInvoke::response() const{
    return m_response;
}

void ShellInvoke::setWaitFor(QString waitFor){
    m_waitFor=waitFor;
}

QString ShellInvoke::fileResponse() const{
    return m_fileResponse;
}
